// 笔试强训_连续子数组最大和

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n = 0; cin >> n;
    vector<int> a(n, 0);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    long long maxsum = a[0];
    long cur = 0, pre = 0;
    for(int i = 0; i < n; i++)
    {
        cur = a[i];
        if(pre > 0)
            cur += pre;
        if(cur > maxsum)
            maxsum = cur;

        pre = cur;
    }
    cout << maxsum << endl;
    return 0;
}